﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using RemoteBank.Entity;
using RemoteBank.BLL;

namespace RemoteBank.GUI
{
    public partial class frmLogin : Form
    {
        frmMain main;
        List<Account> listacc;
        User user;
       
        public frmLogin(frmMain main)
        {
            InitializeComponent();
            this.main = main;
        }

        public bool ValidText()
        {
            if (textBoxUserName.Text == "")
            {
                return false;
            }
            else
            {
                if (textBoxPassword.Text == "")
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }

        }
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            if (this.ValidText())
            {
                
                AccountBLL accountbll = new AccountBLL();
                
                UserBLL userbll = new UserBLL();
                
                if (userbll.Login(textBoxUserName.Text, textBoxPassword.Text))
                {
                    listacc = new List<Account>();
                    user = new User();
                    user = userbll.GetUser(textBoxUserName.Text);
                    listacc = accountbll.GetAllAccount(user.UserID);
                   
                    main.User = user;
                    main.ListAccount = listacc;
                    main.IsLogin = true;
                    Close();
                }
                else
                {
                    MessageBox.Show("Sai user name hoac password");
                }
            }
        }
    }
}
